package com.xxl.job.executor.service.impl;

import cn.jeeweb.common.mybatis.mvc.service.impl.CommonServiceImpl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.xxl.job.executor.enums.GlobalConfEnum;
import com.xxl.job.executor.enums.NumberEnum;
import com.xxl.job.executor.service.IGlobalConfDOService;
import com.xxl.job.executor.entity.GlobalConfDO;
import com.xxl.job.executor.mapper.GlobalConfDOMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * All rights Reserved, Designed By www.jeeweb.cn
 *
 * @version V1.0
 * @package com.xxl.job.executor.service.impl
 * @title: global_conf服务实现
 * @description: global_conf服务实现
 * @author: wondream
 * @date: 2023-09-02 01:06:57
 * @copyright: 2018 www.jeeweb.cn Inc. All rights reserved.
 */
@Transactional
@Service("globalconfdoService")
public class GlobalConfDOServiceImpl extends CommonServiceImpl<GlobalConfDOMapper, GlobalConfDO> implements IGlobalConfDOService {

    @Override
    public String getValueByKey(GlobalConfEnum globalConfEnum, String defaultValue) {
        if (globalConfEnum == null) {
            return defaultValue;
        }
        EntityWrapper<GlobalConfDO> wrapper = new EntityWrapper<GlobalConfDO>();
        wrapper.eq("state", NumberEnum.NUMBER_1.getValue());
        wrapper.eq("item_key", globalConfEnum.getKey());
        GlobalConfDO globalConfDO = selectOne(wrapper);
        if (globalConfDO == null) {
            return defaultValue;
        }
        return StringUtils.isBlank(globalConfDO.getItemValue()) ? defaultValue : globalConfDO.getItemValue();
    }
}